package com.example.mobifin_busticket;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.example.mobifin_busticket.controller.callbacks.ParseListner;
import com.example.mobifin_busticket.controller.networkmanager.NetworkManager;
import com.example.mobifin_busticket.models.BaseRequestEntityForBusTicketSeat;
import com.example.mobifin_busticket.models.RequestEntityBalanceCut;
import com.example.mobifin_busticket.models.RequestEntityUpdateTIN;

public class AsyncTaskForMobifin extends AsyncTask<String, String, Object> {
	Context mContext;
	private NetworkManager networkManager = NetworkManager.getInstance();
	private RequestEntityBalanceCut baseRequestEntityForBusTicket;
	RequestEntityUpdateTIN baseRequestEntityforUpdateTIN;
	ParseListner mListner;
	String strTag, pdMessage;
	boolean isShowing = false, isTINUpdate = false;

	public AsyncTaskForMobifin(Context mContext,
			RequestEntityBalanceCut baseRequestEntityForBusTicket,
			ParseListner mListner, String tag, String pdMessage) {
		this.baseRequestEntityForBusTicket = baseRequestEntityForBusTicket;
		this.mListner = mListner;
		this.mContext = mContext;
		this.pdMessage = pdMessage;
	}

	public AsyncTaskForMobifin(Context mContext,
			RequestEntityUpdateTIN requestEntityForBusTicket,
			ParseListner mListner, String tag, String pdMessage) {
		this.baseRequestEntityforUpdateTIN = requestEntityForBusTicket;
		this.mListner = mListner;
		this.mContext = mContext;
		this.pdMessage = pdMessage;
		this.isTINUpdate = true;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		MyApplication.showProgressDialog(mContext, "Please wait..");
		// if (!isShowing && !MyApplication.getPd().isShowing()) {
		// if (pdMessage.contains("-")) {
		// pdTitleMsg = pdMessage.split(",");
		// pdDestinationmsg = pdTitleMsg[1].split("-");
		// MyApplication.showProgressDialog(mContext, pdTitleMsg[0]);
		// } else {
		// pdTitleMsg = pdMessage.split(",");
		// MyApplication.showProgressDialog(mContext, pdTitleMsg[0]);
		// }
		// }
	}

	protected Object doInBackground(String... params) {
		String httpresponse = "";

		if (isTINUpdate) {
			httpresponse = networkManager
					.makeHttpConnectionToSwitchForUpdateTIn(mContext,
							baseRequestEntityforUpdateTIN);
			Log.d("jsonString", "" + httpresponse);
			return mListner.onParse(httpresponse);

		} else {
			httpresponse = networkManager.makeHttpConnectionToSwitch(mContext,
					baseRequestEntityForBusTicket);
			Log.d("jsonString", "" + httpresponse);
			return mListner.onParse(httpresponse);

		}
	}
}